Palindrome Linked List
Hard
Question
Given the head of a linked list of integers, return True
if it's a palindrome, otherwise return False
.
A linked list is a palindrome if it sequence of nodes reads the same forwards and backwards.
Input: head = [4 -> 7 -> 7 -> 4]
Output: True
Input: head = [4 -> 7 -> 7]
Output: False
Follow up: Could you solve this in O(n) time and O(1) space?
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Which of these linked lists is *not* a palindrome?
[]
[7 -> 11 -> 11]
[1 -> 2 -> 3 -> 2 -> 1]
[1 -> 2 -> 3 -> 3 -> 2 -> 1]
Take a moment to understand the problem and think of your approach before you start coding.